package com.lesso.cyg.sunflower.domain.service;

import com.baomidou.mybatisplus.plugins.Page;
import com.lesso.cyg.sunflower.domain.repository.DeviceRepository;
import com.lesso.cyg.sunflower.infra.assembler.DeviceAssembler;
import com.lesso.cyg.sunflower.pojo.dto.DeviceDTO;
import com.lesso.cyg.sunflower.pojo.dto.DeviceQueryDTO;
import com.lesso.cyg.sunflower.pojo.vo.DeviceVO;
import com.lesso.cyg.sunflower.model.Device;
import org.springframework.stereotype.Service;

/**
 * DeviceDomainService
 *
 * @author cyg
 * @since 2025-07-02
 */
@Service
public class DeviceDomainService {

    private final DeviceRepository deviceRepository;

    public DeviceDomainService(DeviceRepository deviceRepository) {
        this.deviceRepository = deviceRepository;
    }

    public Integer save(DeviceDTO dto) {
        return deviceRepository.save(DeviceAssembler.INSTANCE.dtoToEntity(dto));
    }

    public Page<DeviceVO> page(DeviceQueryDTO dto) {
        return deviceRepository.getPageList(dto);
    }

    public Page<DeviceVO> customPage(DeviceQueryDTO dto) {
        return deviceRepository.getCustomPageList(dto);
    }

    public void deleteById(Long id) {
        deviceRepository.deleteById(id);
    }

    public Integer update(DeviceDTO dto) {
        return deviceRepository.update(DeviceAssembler.INSTANCE.dtoToEntity(dto));
    }
}